//
//  FinderCatListModel.m
//
//  Created by   on 2019/6/4
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "FinderCatListModel.h"


NSString *const kFinderCatListModelTypeRemark = @"typeRemark";
NSString *const kFinderCatListModelId = @"id";
NSString *const kFinderCatListModelIsDelete = @"isDelete";
NSString *const kFinderCatListModelUpdateTime = @"updateTime";
NSString *const kFinderCatListModelTypeName = @"typeName";
NSString *const kFinderCatListModelAddTime = @"addTime";
NSString *const kFinderCatListModelTypeCode = @"typeCode";
NSString *const kFinderCatListModelUpdateUser = @"updateUser";
NSString *const kFinderCatListModelAddUser = @"addUser";


@interface FinderCatListModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation FinderCatListModel

@synthesize typeRemark = _typeRemark;
@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize isDelete = _isDelete;
@synthesize updateTime = _updateTime;
@synthesize typeName = _typeName;
@synthesize addTime = _addTime;
@synthesize typeCode = _typeCode;
@synthesize updateUser = _updateUser;
@synthesize addUser = _addUser;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.typeRemark = [self objectOrNilForKey:kFinderCatListModelTypeRemark fromDictionary:dict];
            self.internalBaseClassIdentifier = [[self objectOrNilForKey:kFinderCatListModelId fromDictionary:dict] doubleValue];
            self.isDelete = [[self objectOrNilForKey:kFinderCatListModelIsDelete fromDictionary:dict] boolValue];
            self.updateTime = [[self objectOrNilForKey:kFinderCatListModelUpdateTime fromDictionary:dict] doubleValue];
            self.typeName = [self objectOrNilForKey:kFinderCatListModelTypeName fromDictionary:dict];
            self.addTime = [[self objectOrNilForKey:kFinderCatListModelAddTime fromDictionary:dict] doubleValue];
            self.typeCode = [self objectOrNilForKey:kFinderCatListModelTypeCode fromDictionary:dict];
            self.updateUser = [self objectOrNilForKey:kFinderCatListModelUpdateUser fromDictionary:dict];
            self.addUser = [self objectOrNilForKey:kFinderCatListModelAddUser fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.typeRemark forKey:kFinderCatListModelTypeRemark];
    [mutableDict setValue:[NSNumber numberWithDouble:self.internalBaseClassIdentifier] forKey:kFinderCatListModelId];
    [mutableDict setValue:[NSNumber numberWithBool:self.isDelete] forKey:kFinderCatListModelIsDelete];
    [mutableDict setValue:[NSNumber numberWithDouble:self.updateTime] forKey:kFinderCatListModelUpdateTime];
    [mutableDict setValue:self.typeName forKey:kFinderCatListModelTypeName];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kFinderCatListModelAddTime];
    [mutableDict setValue:self.typeCode forKey:kFinderCatListModelTypeCode];
    [mutableDict setValue:self.updateUser forKey:kFinderCatListModelUpdateUser];
    [mutableDict setValue:self.addUser forKey:kFinderCatListModelAddUser];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.typeRemark = [aDecoder decodeObjectForKey:kFinderCatListModelTypeRemark];
    self.internalBaseClassIdentifier = [aDecoder decodeDoubleForKey:kFinderCatListModelId];
    self.isDelete = [aDecoder decodeBoolForKey:kFinderCatListModelIsDelete];
    self.updateTime = [aDecoder decodeDoubleForKey:kFinderCatListModelUpdateTime];
    self.typeName = [aDecoder decodeObjectForKey:kFinderCatListModelTypeName];
    self.addTime = [aDecoder decodeDoubleForKey:kFinderCatListModelAddTime];
    self.typeCode = [aDecoder decodeObjectForKey:kFinderCatListModelTypeCode];
    self.updateUser = [aDecoder decodeObjectForKey:kFinderCatListModelUpdateUser];
    self.addUser = [aDecoder decodeObjectForKey:kFinderCatListModelAddUser];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_typeRemark forKey:kFinderCatListModelTypeRemark];
    [aCoder encodeDouble:_internalBaseClassIdentifier forKey:kFinderCatListModelId];
    [aCoder encodeBool:_isDelete forKey:kFinderCatListModelIsDelete];
    [aCoder encodeDouble:_updateTime forKey:kFinderCatListModelUpdateTime];
    [aCoder encodeObject:_typeName forKey:kFinderCatListModelTypeName];
    [aCoder encodeDouble:_addTime forKey:kFinderCatListModelAddTime];
    [aCoder encodeObject:_typeCode forKey:kFinderCatListModelTypeCode];
    [aCoder encodeObject:_updateUser forKey:kFinderCatListModelUpdateUser];
    [aCoder encodeObject:_addUser forKey:kFinderCatListModelAddUser];
}

- (id)copyWithZone:(NSZone *)zone
{
    FinderCatListModel *copy = [[FinderCatListModel alloc] init];
    
    if (copy) {

        copy.typeRemark = [self.typeRemark copyWithZone:zone];
        copy.internalBaseClassIdentifier = self.internalBaseClassIdentifier;
        copy.isDelete = self.isDelete;
        copy.updateTime = self.updateTime;
        copy.typeName = [self.typeName copyWithZone:zone];
        copy.addTime = self.addTime;
        copy.typeCode = [self.typeCode copyWithZone:zone];
        copy.updateUser = [self.updateUser copyWithZone:zone];
        copy.addUser = [self.addUser copyWithZone:zone];
    }
    
    return copy;
}


@end
